﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：QS_LH_JINGUOHXX实体层次
//********************************************************************************//

#region Entity

using System;
using System.Data;
using Entity;
using Oracle.DataAccess.Client;
using Platform.Configuration;
using Platform.Data;

namespace Entity
{
    [Serializable]
    public class QS_LH_JINGUOHXX
    {
        private decimal m_dec_id;

        private string m_str_s_jingbh;

        private string m_str_s_laihanbh;

        private string m_str_s_mubiaoyhh;

        private string m_str_s_yuanyhh;

        /// <summary>
        /// </summary>
        public decimal ID
        {
            get { return m_dec_id; }
            set { m_dec_id = value; }
        }

        /// <summary>
        /// </summary>
        public string S_LAIHANBH
        {
            get { return m_str_s_laihanbh; }
            set { m_str_s_laihanbh = value; }
        }

        /// <summary>
        ///     井编号
        /// </summary>
        public string S_JINGBH
        {
            get { return m_str_s_jingbh; }
            set { m_str_s_jingbh = value; }
        }

        /// <summary>
        ///     原用户
        /// </summary>
        public string S_YUANYHH
        {
            get { return m_str_s_yuanyhh; }
            set { m_str_s_yuanyhh = value; }
        }

        /// <summary>
        ///     过户目标用户
        /// </summary>
        public string S_MUBIAOYHH
        {
            get { return m_str_s_mubiaoyhh; }
            set { m_str_s_mubiaoyhh = value; }
        }
    }
}

#endregion

#region EntityProcess

namespace BLL.Access
{
    //using System.Data.OracleClient;

    public class QS_LH_JINGUOHXXProcess
    {
        #region Field

        protected string conn;

        #endregion

        #region Construction

        public QS_LH_JINGUOHXXProcess()
        {
            conn = ConfigHelper.PlatformConnString;
        }

        #endregion

        #region public

        /// <summary>
        ///     根据QS_LH_JINGUOHXX实体添加或者修改QS_LH_JINGUOHXX信息
        /// </summary>
        public bool InsertOrUpdate(QS_LH_JINGUOHXX QS_LH_JINGUOHXX, OracleTransaction Transaction)
        {
            if (QS_LH_JINGUOHXX.ID == 0)
                InsertQS_LH_JINGUOHXX(QS_LH_JINGUOHXX, Transaction);
            else
                UpdateQS_LH_JINGUOHXX(QS_LH_JINGUOHXX, Transaction);
            return QS_LH_JINGUOHXX.ID == 0 ? false : true;
        }

        /// <summary>
        ///     根据QS_LH_JINGUOHXX实体添加或修改QS_LH_JINGUOHXX信息
        /// </summary>
        public bool InsertOrUpdate(QS_LH_JINGUOHXX QS_LH_JINGUOHXX)
        {
            return InsertOrUpdate(QS_LH_JINGUOHXX, null);
        }


        /// <summary>
        ///     根据QS_LH_JINGUOHXX主键删除QS_LH_JINGUOHXX信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteQS_LH_JINGUOHXX(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_DelQS_LH_JINGUOHXX";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据QS_LH_JINGUOHXX主键删除QS_LH_JINGUOHXX信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteQS_LH_JINGUOHXX(decimal ID)
        {
            return DeleteQS_LH_JINGUOHXX(ID, null);
        }

        /// <summary>
        ///     根据条件删除QS_LH_JINGUOHXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteQS_LH_JINGUOHXXesDynamic(string WhereClause, OracleTransaction Transaction)
        {
            var spName = "CS_DelQS_LH_JINGUOHXXesDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据条件删除QS_LH_JINGUOHXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteQS_LH_JINGUOHXXesDynamic(string WhereClause)
        {
            return DeleteQS_LH_JINGUOHXXesDynamic(WhereClause, null);
        }

        /// <summary>
        ///     根据QS_LH_JINGUOHXX主键选择QS_LH_JINGUOHXX信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>QS_LH_JINGUOHXX信息</returns>
        public QS_LH_JINGUOHXX SelectQS_LH_JINGUOHXX(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_SelQS_LH_JINGUOHXX";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                var QS_LH_JINGUOHXX = PopulateQS_LH_JINGUOHXX(rd);
                rd.Close();
                return QS_LH_JINGUOHXX;
            }
            return null;
        }

        /// <summary>
        ///     根据QS_LH_JINGUOHXX主键选择QS_LH_JINGUOHXX信息
        /// </summary>
        /// <returns>QS_LH_JINGUOHXX信息</returns>
        public QS_LH_JINGUOHXX SelectQS_LH_JINGUOHXX(decimal ID)
        {
            return SelectQS_LH_JINGUOHXX(ID, null);
        }

        /// <summary>
        ///     选择所有QS_LH_JINGUOHXX信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有QS_LH_JINGUOHXX信息</returns>
        public DataTable SelectQS_LH_JINGUOHXXesAll(OracleTransaction Transaction)
        {
            var spName = "CS_SelQS_LH_JINGUOHXXesAll";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }

        /// <summary>
        ///     选择所有QS_LH_JINGUOHXX信息
        /// </summary>
        /// <returns>所有QS_LH_JINGUOHXX信息</returns>
        public DataTable SelectQS_LH_JINGUOHXXesAll()
        {
            return SelectQS_LH_JINGUOHXXesAll(null);
        }

        /// <summary>
        ///     根据条件选择QS_LH_JINGUOHXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>QS_LH_JINGUOHXX信息</returns>
        public DataTable SelectQS_LH_JINGUOHXXesDynamic(string WhereClause, string OrderByExpression,
            OracleTransaction Transaction)
        {
            var spName = "CS_SelQS_LH_JINGUOHXXesDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择QS_LH_JINGUOHXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>QS_LH_JINGUOHXX信息</returns>
        public DataTable SelectQS_LH_JINGUOHXXesDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectQS_LH_JINGUOHXXesDynamic(WhereClause, OrderByExpression, null);
        }


        /// <summary>
        ///     根据条件选择QS_LH_JINGUOHXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>QS_LH_JINGUOHXX信息</returns>
        public DataTable SelectQS_LH_JINGUOHXXesDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize, OracleTransaction Transaction)
        {
            var spName = "CS_SelQS_LH_JINGUOHXXesDynPaged";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择QS_LH_JINGUOHXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>QS_LH_JINGUOHXX信息</returns>
        public DataTable SelectQS_LH_JINGUOHXXesDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize)
        {
            return SelectQS_LH_JINGUOHXXesDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///     根据条件更新QS_LH_JINGUOHXX字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateQS_LH_JINGUOHXXesDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            var result = 0;
            if (UpdateValue == "" || WhereClause == "")
                return 0;
            var spName = "CS_UpdQS_LH_JINGUOHXXDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///     根据条件更新QS_LH_JINGUOHXX字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateQS_LH_JINGUOHXXesDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateQS_LH_JINGUOHXXesDynamic(UpdateValue, WhereClause, null);
        }

        #endregion

        #region Private

        private int InsertQS_LH_JINGUOHXX(QS_LH_JINGUOHXX QS_LH_JINGUOHXX, OracleTransaction Transaction)
        {
            var spName = "CS_InsQS_LH_JINGUOHXX";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = QS_LH_JINGUOHXX.S_LAIHANBH;
            storedParams[1].Value = QS_LH_JINGUOHXX.S_JINGBH;
            storedParams[2].Value = QS_LH_JINGUOHXX.S_YUANYHH;
            storedParams[3].Value = QS_LH_JINGUOHXX.S_MUBIAOYHH;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            QS_LH_JINGUOHXX.ID = Convert.ToInt32(storedParams[4].Value);
            return result;
        }

        private bool UpdateQS_LH_JINGUOHXX(QS_LH_JINGUOHXX QS_LH_JINGUOHXX, OracleTransaction Transaction)
        {
            var spName = "CS_UpdQS_LH_JINGUOHXX";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = QS_LH_JINGUOHXX.S_LAIHANBH;
            storedParams[1].Value = QS_LH_JINGUOHXX.S_JINGBH;
            storedParams[2].Value = QS_LH_JINGUOHXX.S_YUANYHH;
            storedParams[3].Value = QS_LH_JINGUOHXX.S_MUBIAOYHH;
            storedParams[4].Value = QS_LH_JINGUOHXX.ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private QS_LH_JINGUOHXX PopulateQS_LH_JINGUOHXX(IDataReader dr)
        {
            var QS_LH_JINGUOHXX = new QS_LH_JINGUOHXX();
            QS_LH_JINGUOHXX.ID = dr["ID"] == DBNull.Value ? 0 : (decimal) dr["ID"];
            QS_LH_JINGUOHXX.S_LAIHANBH = dr["S_LAIHANBH"] == DBNull.Value ? null : (string) dr["S_LAIHANBH"];
            QS_LH_JINGUOHXX.S_JINGBH = dr["S_JINGBH"] == DBNull.Value ? null : (string) dr["S_JINGBH"];
            QS_LH_JINGUOHXX.S_YUANYHH = dr["S_YUANYHH"] == DBNull.Value ? null : (string) dr["S_YUANYHH"];
            QS_LH_JINGUOHXX.S_MUBIAOYHH = dr["S_MUBIAOYHH"] == DBNull.Value ? null : (string) dr["S_MUBIAOYHH"];
            return QS_LH_JINGUOHXX;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (var i = 0; i < dt.Rows.Count; i++)
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
        }

        #endregion
    }
}

#endregion